package page.actionPage;

import com.alibaba.fastjson2.JSONObject;
import javafx.fxml.FXML;
import lombok.Getter;
import lombok.Setter;
import utils.Constant;
import utils.ControllerUtils;
import utils.DBUtils;


public abstract class ActionPage extends page.BasePage {
    // 与数据库中的 ObjectId 一致
    @Setter
    protected String objectId;
    @Getter
    protected String CHINESE_NAME;
    @Getter
    protected String TYPE;
    @Getter
    protected String ENGLISH_NAME;
    @FXML
    protected TemplateController templateController;
    @Setter
    @Getter
    private String componentText;

    public ActionPage(String englishName, String chineseName, String type) {
        this.CHINESE_NAME = chineseName;
        this.ENGLISH_NAME = englishName;
        this.TYPE = type;
    }

    /*
     * @Author Dongle
     * @Description 运行命令
     * @Date 14:50 2022/6/5
     *
     **/
    public abstract void run(JSONObject data);



    /*
     * @Author Dongle
     * @Description 生成在主界面选择框中的名字
     * @Date 8:34 2022/6/5
     *
     *
     * @return java.lang.String
     **/
    public String getComboxName() {
        if (getCHINESE_NAME() != null && getENGLISH_NAME() != null) {
            return getCHINESE_NAME() + "|" + getENGLISH_NAME();
        } else {
            return null;
        }
    }


    // 初始化
    public abstract void initAction();


    @Override
    public void init() {
        db = new DBUtils(Constant.DB.ACTION_LIST, lcObject);
        initAction();
        // 设置取消按钮
        templateController.cancleButton.setOnMouseClicked(MouseEvent -> ControllerUtils.closePane(root));
    }

}
